<template>
  <div class="login">
    <mt-field label="用户名" placeholder="请输入用户名" v-model="userData.username"></mt-field>
    <mt-field label="密码" placeholder="请输入密码" type="password" v-model="userData.password"></mt-field>
    <div class="login-btn">
      <mt-button type="primary" @click="login">登陆</mt-button>
      <mt-button type="danger">取消</mt-button>
    </div>
  </div>
</template>
<script>
import { login } from "@/api";
export default {
  data() {
    return {
      userData: {
        username: "itcast",
        password: "111111"
      }
    };
  },
  methods: {
    login() {
      login(this.userData).then(res => {
        console.log(res);
        if (res.data.success) {
          var returnUrl = this.$route.params.returnURL;
         if(returnUrl){
            location.href = returnUrl;
         }else{
           this.$router.push({name:'Home'})
         }
        }else{
          this.$toast(res.data.message)
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.login-btn {
  text-align: center;
}
</style>
